package cn.hcbycloud.auth.front.controller;

import cn.hcbycloud.common.imgcode.service.ImageCodeGeneratorService;
import cn.hcbycloud.common.imgcode.service.BaseImageCodeProcessorService;
import cn.hcbycloud.common.mvc.utils.WebUtils;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.ServletWebRequest;

import java.io.IOException;

/**
 * @author gaoh
 * @desc 验证码控制类
 * @date 2022年01月27日 下午 9:08
 */
@RestController
@RequestMapping("/front/code")
@AllArgsConstructor
public class FrontValidateCodeController {
    @Autowired
    BaseImageCodeProcessorService imageCodeProcessorService;
    @Autowired
    ImageCodeGeneratorService imageCodeGeneratorService;
    @GetMapping("/image")
    public void createValidateCode(@RequestParam("uniqueCode") String randomCode) throws IOException {
        ServletWebRequest servlet = new ServletWebRequest(WebUtils.getRequest(), WebUtils.getResponse());
        imageCodeProcessorService.create(servlet,randomCode,imageCodeGeneratorService);
    }
}